<template>
	<view class="container">
		<view class="search">
			<input type="text" placeholder="请输入昵称/团伴号" v-model="searchWord" class="search-input" />
			<image src="/static/image/Index/search-icon.png" mode="" class="search_icon"></image>
			<image src="/static/image/Index/search-clear.png" mode="" @click="handClearWork" class="search_clear"
				v-if="searchWord!=''"></image>
			<view style="font-size: 30rpx;margin-left:30rpx;" @click="searchSubmit">搜索</view>
		</view>
		<view class="search-history" v-if="showHistory">
			<view class="historytxt">
				<view style="font-size: 32rpx;">搜索历史</view>
				<image src="/static/image/Index/search-del.png" mode="" @click="deleteHistory" class="del"></image>
			</view>
			<view class="historylist">
				<view class="listitem" v-for="(item,index) in historyList" :key="index">{{item}}</view>
		<!-- 		<view class="listitem">是发给宝贝啊</view>
				<view class="listitem">爱偷懒的橘猫</view>
				<view class="listitem">一直睡不醒的大侠</view> -->
			</view>
		</view>
		<!-- 有数据 -->
		<view class="content_List">
			<noData style="margin: 0 auto;" v-if="expertList.length < 1" :ndText="'暂无数据'"></noData>
			<view v-else class="content_model" v-for="(item,index) in expertList" :key="index">
				<image :src="item.avatar" mode="" class="model_img"></image>
				<span class="model_time">2小时前在线</span>
				<view class="model_info">
					<view class="info_name">{{item.user_nickname}}</view>
					<view class="info_group">
						<image src="/static/image/Index/girl-icon.png" mode="" class="genderimg"></image>
						<view class="agetext">{{item.age}} {{item.horoscope}}</view>
					</view>
					<image src="/static/image/Index/VIP-icon.png" mode="" class="vipimg"></image>
				</view>
				<view class="littmemodel">
					<image v-for="(ite,index) in item.images.slice(0,5)" :key="index" :src="ite" mode="" class="littleimg">
					</image>
					<view v-if="item.images.length>5" class="extranum">
						+{{ (item.images.length)-5}}
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import noData from '@/components/ben-components/notData/notData.vue'
	export default {
		components: {
			noData
		},
		data() {
			return {
				searchWord: '',
				historyList:[],
				showNo: false,
				showHistory: false,
				littleList: [	],
				expertList: [],

			};
		},

		onLoad() {
        uni.getStorage({
        	key:'historyList',
        	success:(res)=> {
        		this.historyList = res.data
        	}
        })
				console.log(this.historyList)
				if(this.historyList.length==0){
					this.showHistory = false
				}else{
						this.showHistory = true
				}
		},
		methods: {
			handClearWork() {
				this.searchWord = ''
			},
			deleteHistory() {
				uni.showModal({
					title: '提示',
					content: '是否确认删除历史记录？',
					confirmColor: "#000000",
					cancelColor: "#999999",
					success: (res) => {
						if (res.confirm) {
							uni.removeStorageSync('historyList')
							this.historyList = []
							this.showHistory = false
						}
					}
				})
			},

			//搜索
			searchSubmit() {
				
				let params = {
					type: 'interest',
					page: 1,
					list_rows: 10,
					keyword: this.searchWord,
				}
				this.$http.getHomeList(params).then(res => {
					if (res.code === 1) {
						if(res.data.data.length>0){
							this.showNo = false
						}else{
							this.showNo = true
						}
						this.expertList = res.data.data	
						
						this.historyList.push(this.searchWord)
							uni.setStorage({
								key:'historyList',
								data:this.historyList
							})
					} else {
						this.$helper.toast('none', res.msg);
					}
				})
			},

		}
	};
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff !important;
	}
	.container {
		padding: 30rpx;

		.search {
			display: flex;
			align-items: center;
		}

		.search-input {
			position: relative;
			font-size: 28rpx;
			padding-left: 74rpx;
			width: 600rpx;
			height: 78rpx;
			background: #F8F8F8;
			border-radius: 40rpx;
		}

		.search_icon {
			width: 28rpx;
			height: 27rpx;
			position: absolute;
			left: 60rpx;
		}

		.search_clear {
			width: 30rpx;
			height: 30rpx;
			position: absolute;
			right: 150rpx;
		}

		.search-history {
			margin-top: 40rpx;
		}

		.historytxt {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.del {
			width: 34rpx;
			height: 32rpx;
		}

		.historylist {
			margin-top: 30rpx;
			display: flex;
			align-items: center;
			flex-wrap: wrap;
		}

		.listitem {

			height: 60rpx;
			background: #F8F8F8;
			border-radius: 8rpx;
			font-size: 24rpx;
			text-align: center;
			color: #666666;
			line-height: 60rpx;
			margin-right: 24rpx;
			margin-bottom: 24rpx;
			padding: 0 24rpx;

		}

		.content_List {
			display: flex;
			justify-content: space-between;
			margin-top: 40rpx;
			flex-wrap: wrap;
		}

		.content_model {
			position: relative;
			height: 420rpx;
			// margin-right: 20rpx;
			margin-bottom: 20rpx;

		}

		.model_img {
			width: 335rpx;
			height: 420rpx;
			border-top-right-radius: 16rpx;
			border-bottom-left-radius: 16rpx;
		}

		.model_time {
			position: absolute;
			top: 0;
			right: 0;
			font-size: 12rpx;
			text-align: center;
			width: 150rpx;
			line-height: 40rpx;
			height: 40rpx;
			border-top-right-radius: 16rpx;
			border-bottom-left-radius: 16rpx;
			color: #ffffff;
			background: rgba(0, 0, 0, 0.6);

		}

		.model_info {
			display: flex;
			align-items: center;
			position: absolute;
			bottom: 80rpx;
			left: 12rpx;
			font-weight: 500;
		}

		.info_name {
			width: 96rpx;
			font-size: 32rpx;
			color: #fff;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}

		.info_group {
			display: flex;
			align-items: center;
			height: 32rpx;
			background: rgba(0, 0, 0, 0.3);
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			margin-left: 12rpx;

			.genderimg {
				width: 13rpx;
				height: 20rpx;
				margin-left: 8rpx;
			}

			.agetext {
				font-size: 20rpx;
				color: rgba(255, 255, 255, 0.8);
				line-height: 28rpx;
				margin-left: 8rpx;
			}

		}

		.vipimg {
			width: 54rpx;
			height: 28rpx;
			margin-left: 8rpx;
		}

		.littmemodel {
			position: absolute;
			bottom: 12rpx;
			left: 12rpx;
			display: flex;
			align-items: center;
			height: 56rpx;

			.littleimg {
				width: 55rpx;
				height: 55rpx;
				margin-right: 10rpx;
				border-radius: 8rpx;
			}

			.extranum {
				width: 55rpx;
				height: 55rpx;
				border-radius: 8rpx;
				background: rgba(0, 0, 0, 0.3);
				color: #fff;
				text-align: center;
				line-height: 55rpx;
				position: absolute;
				right: 10rpx;
			}
		}

		.normaltxt {
			text-align: center;
			font-size: 28rpx;
			color: rgba(153, 153, 153, 1)
		}
	}
</style>